package cloud.xiangyixiang.www.spring.boot.java.basics.service;

import java.util.Objects;

/**
 * <p>
 * 功能性接口类
 * </p>
 *
 * @author weixin
 * @date 2023/9/16 18:29
 */
@FunctionalInterface
public interface IFeature<T, R> {

    R apply(T t);

    default <V> IFeature<V, R> compose(IFeature<? super V, ? extends T> before) {
        Objects.requireNonNull(before);
        return (V v) -> apply(before.apply(v));
    }

    default <V> IFeature<T, V> andThen(IFeature<? super R, ? extends V> after) {
        Objects.requireNonNull(after);
        return (T t) -> after.apply(apply(t));
    }

    static <T> IFeature<T, T> identity() {
        return t -> t;
    }

}
